package com.demo.bean.controller.column;

import com.demo.bean.service.column.ColumnService;
import com.demo.common.entity.ColumnManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 查询主栏目、次级栏目
 * 作者：孙佳佳
 * 补充：张佑威
 * 分配任务：张改
 * 插入数据：贾冠博
 */
@RestController
public class ColumnController {

    @Autowired
    private ColumnService columnService;

    /**
     * 查询所有主栏目
     * @return
     */
    @GetMapping("/column")
    public ResponseEntity<List<ColumnManagement>> searchAllParent(){
        List<ColumnManagement> columnManagements = columnService.searchAllParent();
        return ResponseEntity.ok(columnManagements);
    }

    /**
     * 根据父id查询所有子栏目
     * @param columnFatherId
     * @return
     */
    @GetMapping("/column/{columnFatherId}")
    public ResponseEntity<List<ColumnManagement>> searchByParentId(@PathVariable Integer columnFatherId){
        List<ColumnManagement> columnManagements = columnService.searchByFatherId(columnFatherId);
        return ResponseEntity.ok(columnManagements);
    }

}
